
#include <types.h>
#include <osal/osal.h>
#include <api/libc/printf.h>
#include <api/libc/string.h>
#include <api/libosd/osd_lib.h>
#include <api/libmp/media_player_api.h>
#include <api/libmp/pe.h>

#include "copper_common/system_data.h"
#include "copper_common/com_api.h"

#include "osdobjs_def.h"
#include "win_com_menu_define.h"
#include "win_com_popup.h"
#include "menus_root.h"

#include "osd_config.h"
#include "string.id"
#include "images.id"
#include "win_com.h"
#include "win_media.h"

#ifdef IMG_2D_TO_3D

/*******************************************************************************
*	extern 
*******************************************************************************/
extern PlayListHandle cur_playlist_image;
extern UINT16 cur_image_idx;
extern IMAGE_SET image_setting;
extern BOOL from_imagesetting;



extern void win_imageslide_osd_onoff(UINT8 onoff);
extern void win_imageslide_show_user_para(UINT8 flag);



/*******************************************************************************
*	Objects definition
*******************************************************************************/
extern CONTAINER	win_imageset_con;

extern CONTAINER imageset_item_con1;
extern CONTAINER imageset_item_con2;
extern CONTAINER imageset_item_con3;
extern CONTAINER imageset_item_con4;
extern CONTAINER imageset_item_con5;

extern TEXT_FIELD	 imageset_title;

extern TEXT_FIELD imageset_item_txtname1;
extern TEXT_FIELD imageset_item_txtname2;
extern TEXT_FIELD imageset_item_txtname3;
extern TEXT_FIELD imageset_item_txtname4;
extern TEXT_FIELD imageset_item_txtname5;

extern TEXT_FIELD imageset_item_txtset1;
extern TEXT_FIELD imageset_item_txtset2;
extern TEXT_FIELD imageset_item_txtset3;
extern TEXT_FIELD imageset_item_txtset4;
extern TEXT_FIELD imageset_item_txtset5;

extern TEXT_FIELD imageset_item_line1;
extern TEXT_FIELD imageset_item_line2;
extern TEXT_FIELD imageset_item_line3;
extern TEXT_FIELD imageset_item_line4;
extern TEXT_FIELD imageset_item_line5;



static VACTION imageset_item_con_keymap(POBJECT_HEAD pObj, UINT32 key);
static PRESULT imageset_item_con_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);

static VACTION imageset_con_keymap(POBJECT_HEAD pObj, UINT32 key);
static PRESULT imageset_con_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);

#undef WIN_SH_IDX
#undef WIN_HL_IDX
#undef WIN_SL_IDX
#undef WIN_GRY_IDX 
#define WIN_SH_IDX	  WSTL_WIN_BODYLEFT_01_HD
#define WIN_HL_IDX	  WSTL_WIN_BODYLEFT_01_HD
#define WIN_SL_IDX	  WSTL_WIN_BODYLEFT_01_HD
#define WIN_GRY_IDX  WSTL_WIN_BODYLEFT_01_HD

#define CON_SH_IDX   WSTL_BUTTON_01_HD
#define CON_HL_IDX   WSTL_BUTTON_05_HD
#define CON_SL_IDX   WSTL_BUTTON_01_HD
#define CON_GRY_IDX  WSTL_BUTTON_07_HD

#define CON_HLSUB_IDX	WSTL_BUTTON_02_HD

#define TXT_SH_IDX   WSTL_BUTTON_01_FG_HD
#define TXT_HL_IDX   WSTL_BUTTON_02_FG_HD
#define TXT_SL_IDX   WSTL_BUTTON_01_FG_HD
#define TXT_GRY_IDX  WSTL_BUTTON_07_HD

#define SEL_SH_IDX   WSTL_BUTTON_01_FG_HD
#define SEL_HL_IDX   WSTL_BUTTON_04_HD
#define SEL_SL_IDX   WSTL_BUTTON_01_FG_HD
#define SEL_GRY_IDX  WSTL_BUTTON_07_HD

#define TITLE_SH_IDX	WSTL_WIN_TITLE_01_HD

#ifndef SD_UI

#define TITLE_L	229//20//229//232
#define TITLE_T	181//30//181//185
#define TITLE_W	550
#define TITLE_H	60

#undef W_L
#undef W_T
#undef W_W
#undef W_H
#undef CON_L
#undef CON_T
#undef CON_W
#undef CON_H
#undef CON_GAP

#define	W_L		TITLE_L //180
#define	W_T	TITLE_T//TITLE_T+TITLE_H
#define	W_W	TITLE_W
#define	W_H	280//300//260//200//218//134//90
#define CON_L	(W_L + 10)//(W_L + 4)
#define CON_T	(W_T + 2 + TITLE_H)//(W_T + 2)
#define CON_W	(W_W - 20)//(W_W - 8)
#define CON_H	40//42


#define CON_GAP	0

#define TXT_L_OF  	2
#define TXT_W  		((CON_W*5)/11)
#define TXT_H		CON_H//42//28
#define TXT_T_OF	((CON_H - TXT_H)/2)

#define SEL_L_OF  (TXT_L_OF + TXT_W)
#define SEL_W  		((CON_W*6)/11)
#define SEL_H		CON_H//42
#define SEL_T_OF	((CON_H - SEL_H)/2)

#else

#define TITLE_L	104//229//232
#define TITLE_T	100//181//185
#define TITLE_W	400
#define TITLE_H	40

#define	W_L		TITLE_L //180
#define	W_T	TITLE_T//TITLE_T+TITLE_H
#define	W_W	TITLE_W
#define	W_H	220//232//200//200//218//134//90
#define CON_L	(W_L + 10)//(W_L + 4)
#define CON_T	(W_T + 2 + TITLE_H)//(W_T + 2)
#define CON_W	(W_W - 20)//(W_W - 8)
#define CON_H	32//42


#define CON_GAP	0

#define TXT_L_OF  	2
#define TXT_W  		((CON_W*5)/11)
#define TXT_H		CON_H//42//28
#define TXT_T_OF	((CON_H - TXT_H)/2)

#define SEL_L_OF  (TXT_L_OF + TXT_W)
#define SEL_W  		((CON_W*6)/11)
#define SEL_H		CON_H//42
#define SEL_T_OF	((CON_H - SEL_H)/2)

#endif


#define LDEF_CON(root, varCon,nxtObj,ID,IDl,IDr,IDu,IDd,l,t,w,h,hl,conobj,focusID)		\
    DEF_CONTAINER(varCon,root,nxtObj,C_ATTR_ACTIVE,0, \
    ID,IDl,IDr,IDu,IDd, l,t,w,h, CON_SH_IDX,CON_HL_IDX,CON_SL_IDX,CON_GRY_IDX,   \
    imageset_item_con_keymap,imageset_item_con_callback,  \
    conobj, ID,1)
    
#define LDEF_TXT(root,varTxt,nxtObj,l,t,w,h,resID)		\
    DEF_TEXTFIELD(varTxt,root,nxtObj,C_ATTR_ACTIVE,0, \
    0,0,0,0,0, l,t,w,h, TXT_SH_IDX,TXT_HL_IDX,TXT_SL_IDX,TXT_GRY_IDX,   \
    NULL,NULL,  \
    C_ALIGN_LEFT| C_ALIGN_VCENTER, 0,0,resID,NULL)

#define LDEF_TXTSET(root,varTxt,nxtObj,ID,IDl,IDr,IDu,IDd,l,t,w,h,resID,str)		\
    DEF_TEXTFIELD(varTxt,root,nxtObj,C_ATTR_ACTIVE,0, \
    ID,IDl,IDr,IDu,IDd, l,t,w,h, SEL_SH_IDX,SEL_HL_IDX,SEL_SL_IDX,SEL_GRY_IDX,   \
    NULL,NULL,  \
    C_ALIGN_CENTER| C_ALIGN_VCENTER, 20,0,resID,str)
    
#define LDEF_MENU_ITEM_SEL(root,varCon,nxtObj,varTxt,varTxtset,ID,IDu,IDd,\
						l,t,w,h,resIDname,resIDset,setstr) \
    LDEF_CON(&root,varCon,nxtObj,ID,ID,ID,IDu,IDd,l,t,w,h,CON_HL_IDX,&varTxt,ID)   \
    LDEF_TXT(&varCon,varTxt,&varTxtset,l + TXT_L_OF,t + TXT_T_OF,TXT_W,TXT_H,resIDname)    \
    LDEF_TXTSET(&varCon,varTxtset,  NULL        ,1,1,1,1,1,l + SEL_L_OF ,t + SEL_T_OF,SEL_W-1,SEL_H,resIDset,setstr)


#define LDEF_MENU_ITEM_TXT(root,varCon,nxtObj,varTxt,ID,IDu,IDd,\
						l,t,w,h,resID) \
    LDEF_CON(&root,varCon,nxtObj,ID,ID,ID,IDu,IDd,l,t,w,h,CON_HLSUB_IDX,&varTxt,ID)   \
    LDEF_TXT(&varCon,varTxt,NULL,l,t + TXT_T_OF,W_W-8,TXT_H,resID)
    

DEF_TEXTFIELD(imageset_title,&win_imageset_con,&imageset_item_con1,C_ATTR_ACTIVE,0, \
    0,0,0,0,0,TITLE_L,TITLE_T ,TITLE_W,TITLE_H, TITLE_SH_IDX,TITLE_SH_IDX,TITLE_SH_IDX,TITLE_SH_IDX,   \
    NULL,NULL,  \
    C_ALIGN_CENTER | C_ALIGN_VCENTER, 0,0,RS_IMAGE_SETTING,NULL)
    
LDEF_MENU_ITEM_SEL(win_imageset_con,imageset_item_con1,&imageset_item_con2,imageset_item_txtname1,imageset_item_txtset1, 1, 5, 2, \
		CON_L, CON_T + (CON_H + CON_GAP)*0, CON_W, CON_H, RS_IMAGE_SETTING_RESOLUTION, 0, display_strs[5])

LDEF_MENU_ITEM_SEL(win_imageset_con,imageset_item_con2,&imageset_item_con3,imageset_item_txtname2,imageset_item_txtset2, 2, 1, 3, \
		CON_L, CON_T + (CON_H + CON_GAP)*1, CON_W, CON_H, RS_IMAGE_SETTING_FILE_TYPE, 0, display_strs[1])

LDEF_MENU_ITEM_SEL(win_imageset_con,imageset_item_con3,&imageset_item_con4,imageset_item_txtname3,imageset_item_txtset3, 3, 2, 4, \
		CON_L, CON_T + (CON_H + CON_GAP)*2, CON_W, CON_H, RS_IMAGE_SETTING_SLIDE_OSD_ONOFF, 0, display_strs[2])

#if 1
LDEF_MENU_ITEM_SEL(win_imageset_con,imageset_item_con4,&imageset_item_con5,imageset_item_txtname4,imageset_item_txtset4, 4, 3, 5, \
		CON_L, CON_T + (CON_H + CON_GAP)*3, CON_W, CON_H, RS_IMAGE_SETTING_3D_ONOFF, 0, display_strs[3])

LDEF_MENU_ITEM_SEL(win_imageset_con,imageset_item_con5,NULL,imageset_item_txtname5,imageset_item_txtset5, 5, 4, 1, \
		CON_L, CON_T + (CON_H + CON_GAP)*4, CON_W, CON_H, RS_IMAGE_SETTING_3D_OUTPUT_FORMAT, 0, display_strs[4])
#else
LDEF_MENU_ITEM_SEL(win_imageset_con,imageset_item_con4,NULL,imageset_item_txtname4,imageset_item_txtset4, 4, 3, 1, \
		CON_L, CON_T + (CON_H + CON_GAP)*3, CON_W, CON_H, RS_IMAGE_SETTING_3D_ONOFF, 0, display_strs[3])
#endif

DEF_CONTAINER(win_imageset_con,NULL,NULL,C_ATTR_ACTIVE,0, \
    0,0,0,0,0, W_L,W_T,W_W,W_H, WIN_SH_IDX,WIN_HL_IDX,WIN_SL_IDX,WIN_GRY_IDX,   \
    imageset_con_keymap,imageset_con_callback,  \
    (POBJECT_HEAD)&imageset_title, 3,0)

/*******************************************************************************
*	Local functions & variables define
*******************************************************************************/
CONTAINER* imageset_items[] =
{
	&imageset_item_con1,
	&imageset_item_con2,
	&imageset_item_con3,
	&imageset_item_con4,
	&imageset_item_con5,
};

POBJECT_HEAD imageset_item_name[] =
{
	(POBJECT_HEAD)&imageset_item_txtname1,
	(POBJECT_HEAD)&imageset_item_txtname2,
	(POBJECT_HEAD)&imageset_item_txtname3,
	(POBJECT_HEAD)&imageset_item_txtname4,
	(POBJECT_HEAD)&imageset_item_txtname5,
};

POBJECT_HEAD imageset_item_set[] =
{
	(POBJECT_HEAD)&imageset_item_txtset1,
	(POBJECT_HEAD)&imageset_item_txtset2,
	(POBJECT_HEAD)&imageset_item_txtset3,
	(POBJECT_HEAD)&imageset_item_txtset4,
	(POBJECT_HEAD)&imageset_item_txtset5,
};

enum{
MENU_IMAGE_SET_RESOLUTION=1,
MENU_IMAGE_SET_FILE_TYPE,
MENU_IMAGE_SET_OSD_ONOFF,
MENU_IMAGE_SET_3D_ONOFF,
MENU_IMAGE_SET_3D_OUTPUT_FORMAT,
};

/*******************************************************************************
*	key mapping and event callback definition
*******************************************************************************/

static void win_imageset_item_active_control(void)
{
#if 0
    if(IMAGE_SET_ON==image_setting.image_3d_onoff)
    {
    	OSD_SetAttr(&imageset_item_con5, C_ATTR_ACTIVE);
        OSD_SetAttr(&imageset_item_txtname5, C_ATTR_ACTIVE);
        OSD_SetAttr(&imageset_item_txtset5, C_ATTR_ACTIVE);
    } 
    else
    {
    	OSD_SetAttr(&imageset_item_con5, C_ATTR_INACTIVE);
        OSD_SetAttr(&imageset_item_txtname5, C_ATTR_INACTIVE);
        OSD_SetAttr(&imageset_item_txtset5, C_ATTR_INACTIVE);
    }  
#else
    //not show 3D output format selection
    OSD_SetAttr(&imageset_item_con5, C_ATTR_HIDDEN);
    OSD_SetAttr(&imageset_item_txtname5, C_ATTR_HIDDEN);
    OSD_SetAttr(&imageset_item_txtset5, C_ATTR_HIDDEN);
#endif

    OSD_TrackObject(&win_imageset_con,C_UPDATE_ALL );
    
    return;
}

static void win_imageset_resolution_string()
{
	INT8 temp[128];
	char image_name[FULL_PATH_SIZE] = {0};
    FileInfo file_node;
    struct image_info imageinfo;
    
    get_file_from_play_list(cur_playlist_image, cur_image_idx, &file_node);
	win_get_fullname(image_name, file_node.path, file_node.name);
    win_get_fileinfo(image_name, (UINT32)&imageinfo);
    sprintf(temp,"%dX%d",imageinfo.width, imageinfo.height);
	
	ComAscStr2Uni(temp, display_strs[5]);
}

static void win_imageset_filetype_string()
{
	INT8 temp[128];	
    char image_name[FULL_PATH_SIZE];
    FileInfo file_node;
    
    get_file_from_play_list(cur_playlist_image, cur_image_idx, &file_node);
	if(F_BMP==file_node.filetype)
        sprintf(temp,"BMP");
    else if(F_JPG==file_node.filetype)
        sprintf(temp,"JPG");
    else
        sprintf(temp,"Unknown");

	ComAscStr2Uni(temp, display_strs[1]);
}


static void win_imageset_osdonoff_string(INT8 input)
{
	INT8 temp[128];

    if(IMAGE_SET_ON==input)
	    sprintf(temp, "ON", input);
    else
        sprintf(temp, "OFF", input);
	
	ComAscStr2Uni(temp, display_strs[2]);
}

static void win_imageset_3d_onoff_string(INT8 input)
{
	INT8 temp[128];

   if(IMAGE_SET_ON==input)
	    sprintf(temp, "ON", input);
    else
        sprintf(temp, "OFF", input);
						
	ComAscStr2Uni(temp, display_strs[3]);
}
                        
static void win_imageset_3d_output_string(INT8 input)
{
	INT8 temp[128];

    if(IMAGE_SET_3DOUTPUT_TB==input)
	   sprintf(temp, "Top/Bottom",input);
	else if(IMAGE_SET_3DOUTPUT_LR==input)
		sprintf(temp, "Left/Right",input);
	else if(IMAGE_SET_3DOUTPUT_RB==input)
		sprintf(temp, "Red/Blue",input);
	else
		sprintf(temp, "Top/Bottom",input);
						
	ComAscStr2Uni(temp, display_strs[4]);
}

static VACTION imageset_item_con_keymap(POBJECT_HEAD pObj, UINT32 key)
{
	VACTION act;
	
	switch(key)
	{
	case V_KEY_RIGHT:
		act = VACT_INCREASE;
		break;		
	case V_KEY_LEFT:		
		act = VACT_DECREASE;
		break;		
	case V_KEY_ENTER:
		act = VACT_ENTER;
		break;		
	default:	
		act = VACT_PASS;
		break;
	}
	
	return act;

}

void win_imageset_enter_key(POBJECT_HEAD pObj,UINT8 id)
{
	OSD_RECT rect;
	COM_POP_LIST_PARAM_T param;
	
	rect.uLeft=CON_L+TXTS_L_OF;
	rect.uWidth=TXTS_W;
	rect.uHeight=250;
	param.selecttype = POP_LIST_SINGLESELECT;
	switch(id)
	{
		case MENU_IMAGE_SET_OSD_ONOFF:
			#ifndef SD_UI
			rect.uHeight = 300;
			rect.uTop=CON_T + (CON_H + CON_GAP)*3;
			#else
			rect.uHeight = 180;
			rect.uTop=CON_T + (CON_H + CON_GAP)*3;
			#endif
			
			param.cur=image_setting.image_osd_onoff;
			image_setting.image_osd_onoff = win_com_open_sub_list(POP_LIST_IMAGE_SET,&rect,&param);
			win_imageset_osdonoff_string(image_setting.image_osd_onoff);
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			break;
		case MENU_IMAGE_SET_3D_ONOFF:
			#ifndef SD_UI
			rect.uHeight = 300;
			rect.uTop=CON_T + (CON_H + CON_GAP)*4;
			#else
			rect.uHeight = 180;
			rect.uTop=CON_T + (CON_H + CON_GAP)*4;
			#endif
			
			param.cur=image_setting.image_3d_onoff;
 			image_setting.image_3d_onoff = win_com_open_sub_list(POP_LIST_IMAGE_SET,&rect,&param);
 			win_imageset_3d_onoff_string(image_setting.image_3d_onoff);
            win_imageset_item_active_control();
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			break;
		case MENU_IMAGE_SET_3D_OUTPUT_FORMAT:
			#ifndef SD_UI
			rect.uHeight = 300;
			rect.uTop=CON_T + (CON_H + CON_GAP)*5;
			#else
			rect.uHeight = 180;
			rect.uTop=CON_T + (CON_H + CON_GAP)*5;
			#endif
			
			param.cur=image_setting.image_3d_output_format;
 			image_setting.image_3d_output_format = win_com_open_sub_list(POP_LIST_IMAGE_SET,&rect,&param);
 			win_imageset_3d_output_string(image_setting.image_3d_output_format);
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			break;
        default:
            break;
	}

    return;
}

void win_imageset_left_key(POBJECT_HEAD pObj,UINT8 id)
{
	switch(id)
	{
		case MENU_IMAGE_SET_OSD_ONOFF:
			if(IMAGE_SET_OFF==image_setting.image_osd_onoff)
			{
				image_setting.image_osd_onoff = IMAGE_SET_ON;
			}
			else
			{
				image_setting.image_osd_onoff = IMAGE_SET_OFF;
			}
			win_imageset_osdonoff_string(image_setting.image_osd_onoff);
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			break;
        case MENU_IMAGE_SET_3D_ONOFF:
			if(IMAGE_SET_OFF==image_setting.image_3d_onoff)
			{
				image_setting.image_3d_onoff = IMAGE_SET_ON;
			}
			else
			{
				image_setting.image_3d_onoff = IMAGE_SET_OFF;
			}
			win_imageset_3d_onoff_string(image_setting.image_3d_onoff);
            win_imageset_item_active_control();
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			break;    
		case MENU_IMAGE_SET_3D_OUTPUT_FORMAT:
			if(IMAGE_SET_3DOUTPUT_RB==image_setting.image_3d_output_format)
			{
				image_setting.image_3d_output_format = IMAGE_SET_3DOUTPUT_LR;
			}
            else if(IMAGE_SET_3DOUTPUT_LR==image_setting.image_3d_output_format)
			{
				image_setting.image_3d_output_format = IMAGE_SET_3DOUTPUT_TB;
			}
            else if(IMAGE_SET_3DOUTPUT_TB==image_setting.image_3d_output_format)
			{
				image_setting.image_3d_output_format = IMAGE_SET_3DOUTPUT_RB;
			}
			win_imageset_3d_output_string(image_setting.image_3d_output_format);
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			break;
        default:
            break;
	}

    return;
}

void win_imageset_right_key(POBJECT_HEAD pObj,UINT8 id)
{
	switch(id)
	{
		case MENU_IMAGE_SET_OSD_ONOFF:
			if(IMAGE_SET_OFF==image_setting.image_osd_onoff)
			{
				image_setting.image_osd_onoff = IMAGE_SET_ON;
			}
			else
			{
				image_setting.image_osd_onoff = IMAGE_SET_OFF;
			}
			win_imageset_osdonoff_string(image_setting.image_osd_onoff);
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			break;
        case MENU_IMAGE_SET_3D_ONOFF:
			if(IMAGE_SET_OFF==image_setting.image_3d_onoff)
			{
				image_setting.image_3d_onoff = IMAGE_SET_ON;
			}
			else
			{
				image_setting.image_3d_onoff = IMAGE_SET_OFF;
			}
			win_imageset_3d_onoff_string(image_setting.image_3d_onoff);
            win_imageset_item_active_control();
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			break;    
		case MENU_IMAGE_SET_3D_OUTPUT_FORMAT:
			if(IMAGE_SET_3DOUTPUT_TB==image_setting.image_3d_output_format)
			{
				image_setting.image_3d_output_format = IMAGE_SET_3DOUTPUT_LR;
			}
			else if(IMAGE_SET_3DOUTPUT_LR==image_setting.image_3d_output_format)
			{
				image_setting.image_3d_output_format = IMAGE_SET_3DOUTPUT_RB;
			}
            else if(IMAGE_SET_3DOUTPUT_RB==image_setting.image_3d_output_format)
			{
				image_setting.image_3d_output_format = IMAGE_SET_3DOUTPUT_TB;
			}
			win_imageset_3d_output_string(image_setting.image_3d_output_format);
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			break;
        default:
            break;
	}

    return;
}

void win_imageset_key_proc(POBJECT_HEAD pObj, VACTION unact)
{
    UINT8 id;
    UINT8 image_3d_osdonoff_old, image_3d_osdonoff_new;
    UINT8 image_3d_onoff_old, image_3d_onoff_new;
    UINT8 image_3d_output_format_old, image_3d_output_format_new;
    UINT8 back_saved;
    
    id = OSD_GetObjID(pObj);
    image_3d_osdonoff_old = image_setting.image_osd_onoff;
    image_3d_onoff_old = image_setting.image_3d_onoff;
    image_3d_output_format_old =  image_setting.image_3d_output_format;

    if(unact == VACT_ENTER)
	{
		win_imageset_enter_key(pObj,id);
	}
	else if(unact == VACT_DECREASE)
	{
		win_imageset_left_key(pObj,id);
	}
	else if(unact == VACT_INCREASE)
	{
		win_imageset_right_key(pObj,id);
	}

    image_3d_osdonoff_new = image_setting.image_osd_onoff;
    image_3d_onoff_new = image_setting.image_3d_onoff;
    image_3d_output_format_new =  image_setting.image_3d_output_format;
    if(image_3d_osdonoff_new != image_3d_osdonoff_old)
    {
        win_imageslide_osd_onoff(image_3d_osdonoff_new);
    }
    if(image_3d_onoff_new != image_3d_onoff_old)
    {
        if(IMAGE_SET_ON==image_3d_onoff_new)
        {
            win_compopup_init(WIN_POPUP_TYPE_SMSG);
    		win_compopup_set_frame(200, 200, 200, 100);
    		win_compopup_set_msg(NULL, NULL,RS_DISPLAY_PLEASE_WAIT);
    		win_compopup_open_ext(&back_saved);
        }
        image_set_disp_param(image_setting.image_3d_onoff, image_setting.image_3d_output_format, 60, 20, 60);
        image_2d_to_3d_swap(image_3d_onoff_new);
        if(IMAGE_SET_ON==image_3d_onoff_new)
        {
            osal_task_sleep(50);
    		win_compopup_smsg_restoreback();
        }
        win_imageslide_show_user_para(TRUE);
    }
    if(image_3d_output_format_new!= image_3d_output_format_old)
    {
        win_compopup_init(WIN_POPUP_TYPE_SMSG);
		win_compopup_set_frame(200, 200, 200, 100);
		win_compopup_set_msg(NULL, NULL,RS_DISPLAY_PLEASE_WAIT);
		win_compopup_open_ext(&back_saved);
        image_3d_user_option(image_3d_output_format_new, 60, 20, 60);
		win_compopup_smsg_restoreback();
    }    


    return;
}

static PRESULT imageset_item_con_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	PRESULT ret = PROC_PASS;
	UINT8	unact;

	switch(event)
	{	
	case EVN_UNKNOWN_ACTION:
		unact = (VACTION)(param1>>16) ;
        win_imageset_key_proc(pObj,unact);
		ret = PROC_LOOP;
		break;
	}
	return ret;

}

static VACTION imageset_con_keymap(POBJECT_HEAD pObj, UINT32 key)
{
	VACTION act;
	
	switch(key)
	{
		case V_KEY_EXIT:
		case V_KEY_MENU:
		case V_KEY_INFOR:
			act = VACT_CLOSE;
			break;		
		case V_KEY_ENTER:
			act = VACT_ENTER;
			break;		
		default:	
			act = OSD_ContainerKeyMap(pObj,key);
	}
	
	return act;
}

static PRESULT imageset_con_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	PRESULT ret = PROC_PASS;
	UINT8	unact;
	UINT32 i;
	BOOL image_flag;
	CONTAINER* cont = (CONTAINER*)pObj;
	UINT8	id = OSD_GetObjID(pObj);
	int next_image;
	
	switch(event)
	{
	case EVN_PRE_OPEN:	
        OSD_SetAttr(&imageset_item_con1, C_ATTR_INACTIVE); 
        OSD_SetAttr(&imageset_item_con2, C_ATTR_INACTIVE); 
        OSD_SetAttr(&imageset_item_txtset1, C_ATTR_INACTIVE); 
        OSD_SetAttr(&imageset_item_txtset2, C_ATTR_INACTIVE); 
        
        win_imageset_item_active_control();
    	win_imageset_resolution_string();
    	win_imageset_filetype_string();
    	win_imageset_osdonoff_string(image_setting.image_osd_onoff);
    	win_imageset_3d_onoff_string(image_setting.image_3d_onoff);
        win_imageset_3d_output_string(image_setting.image_3d_output_format);
        break;
	case EVN_POST_OPEN:
        OSD_TrackObject(&win_imageset_con,C_UPDATE_ALL );
		break;
	case EVN_MSG_GOT:
		break;
	case EVN_PRE_CLOSE:
#if 0
        next_image = get_next_index_from_play_list(cur_playlist_image);
		if(next_image != -1)
		{
			cur_image_idx = next_image;
			image_abort();
			set_play_list_info(cur_playlist_image,&cur_image_idx,NULL);
	    }
#endif
        from_imagesetting = TRUE;
		unact = (VACTION)(param1>>16);
        ret = PROC_PASS;	
		break;
	case EVN_POST_CLOSE:
		break;
	}
	return ret;
}

UINT8 win_imageset_get_num()
{
	UINT8 ID=OSD_GetFocusID((POBJECT_HEAD)&win_imageset_con);
	UINT8 num=0;
	
	switch(ID)
	{
		case MENU_IMAGE_SET_OSD_ONOFF:
			num=2;
			break;
		case MENU_IMAGE_SET_3D_ONOFF:
			num=2;
			break;
		case MENU_IMAGE_SET_3D_OUTPUT_FORMAT:
			num=3;
			break;
		default:
            break;
	}
	return num;
}

VACTION comlist_menu_imageset_listkeymap(POBJECT_HEAD pObj, UINT32 vkey)
{
	VACTION act = VACT_PASS;

	switch(vkey)
	{
	case V_KEY_UP:
		act = VACT_CURSOR_UP;
		break;        
	case V_KEY_DOWN:
		act = VACT_CURSOR_DOWN;
		break; 
	case V_KEY_P_UP:
		act = VACT_CURSOR_PGUP;
		break; 
	case V_KEY_P_DOWN:
		act = VACT_CURSOR_PGDN;
		break; 
	case V_KEY_ENTER:
		act = VACT_SELECT;
		break;
	}
				
	return act;    
}

VACTION comlist_menu_imageset_winkeymap(POBJECT_HEAD pObj, UINT32 vkey)
{
	PRESULT ret = VACT_PASS;
	switch(vkey)
	{
	case V_KEY_MENU:
	case V_KEY_EXIT:
	    ret = VACT_CLOSE;              
	}
	
	return ret;
}

PRESULT comlist_menu_imageset_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	INT16 i,wTop;
	UINT8 id;
	char str_len;
    	OBJLIST* ol;
	INT8 temp[4];
	
	PRESULT cbRet = PROC_PASS;

    	ol = (OBJLIST*)pObj;
	
	if(event==EVN_PRE_DRAW)
	{
		id=OSD_GetFocusID((POBJECT_HEAD)&win_imageset_con);
		switch(id)
		{
			case MENU_IMAGE_SET_OSD_ONOFF:
            case MENU_IMAGE_SET_3D_ONOFF:
			    	wTop = OSD_GetObjListTop(ol);
			    	for(i=0;i<ol->wDep && (i+wTop)<ol->wCount;i++)
			    	{
			    		if(IMAGE_SET_OFF ==  i+wTop)
						    sprintf(temp, "OFF",  i+wTop);
    					else
    						sprintf(temp, "ON",  i+wTop);

					    win_comlist_set_str(i + wTop,temp,NULL,0);
			    	}
				break;
			case MENU_IMAGE_SET_3D_OUTPUT_FORMAT:
			    	wTop = OSD_GetObjListTop(ol);
			    	for(i=0;i<ol->wDep && (i+wTop)<ol->wCount;i++)
			    	{
			    		if(IMAGE_SET_3DOUTPUT_TB ==  i+wTop)
    						sprintf(temp, "Top/Bottom",  i+wTop);
    					else if(IMAGE_SET_3DOUTPUT_LR ==  i+wTop)
    						sprintf(temp, "Left/Right",  i+wTop);
    					else if(IMAGE_SET_3DOUTPUT_RB ==  i+wTop)
    						sprintf(temp, "Red/Blue",  i+wTop);
    					else
    						sprintf(temp, "Top/Bottom",  i+wTop);

					    win_comlist_set_str(i + wTop,temp,NULL,0);
			    	}
				break;
			default:
                break;
		}
	}
	else if(event == EVN_POST_CHANGE)
	{
		cbRet = PROC_LEAVE;
	}

	return cbRet;
}

#endif
